import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText


class SendEmail:
    user = '',
    password = ''

    # 初始化魔法方法
    def __init__(self):
        # 初始化邮箱数据
        # 发送人邮箱
        self.user = 'rycy@vip.qq.com'
        # 发送密钥 授权码
        self.password = 'uessfeddfbgqdhgh'

    def send_mail(self, to_user, title, content):
        # 构建邮件体
        msg = MIMEMultipart()
        # 邮件标题
        msg['Subject'] = title
        # 发件人
        msg['From'] = self.user
        # 收件人
        msg['To'] = to_user
        # 构建内容
        part = MIMEText(f'{str(content)}', 'html', 'utf-8')
        msg.attach(part)
        # print(msg)

        # 发送逻辑
        # 建立连接对象
        s = smtplib.SMTP_SSL('smtp.qq.com', 465)

        # 登录邮箱
        s.login(self.user, self.password)
        # 发送操作
        s.sendmail(self.user, to_user, msg.as_string())
        # 关闭连接
        s.close()
